﻿// clang-format off
#include <VFAdapterAPIs.h>
#include <iostream>
#include <cassert>
#include <boost/program_options.hpp>
#include <format>
#include <boost/algorithm/string.hpp>
#include <Windows.h>
#include <test.h>

int main(int argc, char **argv) {

  try {
    namespace bo = boost::program_options;
    bo::options_description desc(
        "天工接口验证程序,允许的操作",200);
    // clang-format off
    desc.add_options()("help,h", "显示帮助信息")
    // 一期接口
    ("link,l", "连接天工CAD")
    ("ctPt,p", bo::value<std::string>()->notifier(tt::CreatePoint),"创建点,--ctPt x,y,z")
    ("cvCvi", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CvCv_IntersectPoint),"计算两曲线交点，--cvcvi curveId0 curveId1")
    ("gtEntTp,g",bo::value<std::string>()->notifier(tt::TestGetEntityType),"获得类型,-g geomId")
    ("selByTag,s",bo::value<std::string>()->notifier(tt::TestSelByTag),"使ID指向的几何实体加入选择集,-s geomId")
    ("clrSSet,c","清空选择集")
    ("selSingle",bo::value<int>()->notifier(tt::TestSelectInteractive),"交互式筛选并返回对象,参数为筛选类型。点为1、曲线为2、面为3、链为4、体为5。")
    ("ctOfsCv",bo::value<std::vector< std::string>>()->multitoken()->notifier(tt::Vf_CreateOffsetCurve),"曲线在曲面上偏置--ctOfsCv" )
    ("cvSurfi",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::Vf_CreateCurveSurfaceIntersection),"曲线与曲面求交--cvSurfi")
    ("surfSurfi", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestIntersect_S2S),"计算两曲面交点，如--surfSurfi 0 1,计算曲面0和曲面1的交点")
    // 二期接口
    ("ofsSurf",bo::value<std::vector< std::string>>()->multitoken()->notifier(tt::Vf_OffsetSurface), "曲面沿法线偏置--ofsSurf 0 0.1" )
    ("ctMiSurf", bo::value<std::vector< std::string>>()->multitoken()->notifier(tt::CreateMirrorSurface), "镜像创建面--ctMiSurf 1 2")
    ("ctSpCv", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::Vf_CreateSplineCurve),"样条曲线--ctSpCv")
    ("ctSurfFill", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateSurfaceByFill),"边界填充曲面--ctSurfFill 1 2 3" )
    ("ctCvOnSurf", bo::value<std::string>()->notifier(tt::CreateCurveOnSurfaceByTwoPoints), "曲面上两点创建曲线--ctCvOnSurf x1 y1 z1 x2 y2 z2 faceId;其中坐标可输入为坐标数组，中间以逗号分隔")
    ("ctMiCv", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateMirrorCurve), "镜像创建曲线--ctMiCv 1 3" )
    ("ctCvByProj", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateCurveByProjection), "投影创建投影曲线--ctCvByProj 1 3" )
    ("ctCvByThken", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateBodyWithThickedSurface), "通过曲面加厚创建体--ctCvByThken 1 3" )
    ("calSurSL", bo::value<std::string>()->multitoken()->notifier(tt::CalSurfaceAreaAndPerimeter), "计算曲面的周长和面积--CalSurSL 1 " )
    ("ctSurByLoft", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateSurfaceByLoft), "根据多截面曲线创建面--ctSurByLoft 1 " )
    ("cSurfM", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CalSurfaceMass), "计算曲面质量--cSurfM faceid dense : example --cSurfM 1 1.0" )
    ("cSurfGravity",bo::value<std::string>()->notifier(tt::CalcSurfGravity),"计算曲面重心--cSurfGravity faceId")
    ("selMul", bo::value<int>()->notifier(tt::TestSelMul), "交互式选择多个对象并返回对象集,参数为筛选类型。点为1、曲线为2、面为3、链为4、体为5。 " )
    ("ctSurfMerge", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateSurfaceMerge), "曲面合并--ctSurfMerge 0 1 2 " )
    ("ptOnCv",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestPointOnCurve),"点是否在线上,--ptOnCv ptId cvId")
    ("ptOnSurf",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestPointOnSurface),"点是否在曲面上 --ptOnSurf ptId surfId")
    ("ptOnSurf2",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestPointOnSurface2),"点是否在曲面上 --ptOnSurf2 x y z surfId")
    // 三期接口
    ("getPtOnSurf",bo::value<std::string>()->notifier(tt::TestMousePtOnSurface),"交互式在曲面上取点 --getPtOnSurf surfId")
    ("miObj",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestMirrorObject),"镜像特征,--miObj objId mirrorPlaneID")
    ("ctCompCv",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreateComponentCv),"创建复合曲线,--ctCompCv id0 id1 id2")
    ("cvTrim",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCurveTrim),"曲线裁剪,--cvTrim orgCvId trimCvId")
    ("cvPtByU",bo::value<std::string>()->notifier(tt::TestCtPtByU),"按参数取曲线点,--cvPtByU cvId,u")
    ("cvPtByUV",bo::value<std::string>()->notifier(tt::TestCtPtByUV),"按参数取曲面点,--cvPtByUV surfId,u,v")
    ("ctFuncCv",bo::value<std::string>()->notifier(tt::TestCtFuncCurve),"创建参数曲线,--TestCtFuncCurve cvType;exp0;exp1;exp2")
    ("chWidclr", bo::value<std::string>()->notifier(tt::TestChWidClr),"改变宽度和颜色,--chWidclr cvId ")
    ("restoreObj",bo::value<std::string>()->notifier(tt::TestRestoreWidClr),"恢复宽度和颜色,--restoreObj cvId")
    ("ctCoordSysById", bo::value<std::string>()->notifier(tt::TestCtCoordSysById), "创建坐标系,--ctCoordSysById faceid,ptid,lineid,startang,dirang,seglen")
    ("removeObj",bo::value<std::string>()->notifier(tt::TestRemoveObj),"删除对象,--removeObj objId")
    // 三批增加的四个接口
    ("batchChWidClr",bo::value<std::string>()->notifier(tt::TestBatchChClrWid),"批量改变宽度和颜色, example --batchChWidClr 1,2,3")
    ("batchClearWidClr",bo::value<std::string>()->notifier(tt::TestBatchClearClrWid),"批量清除宽度和颜色, example --batchClearWidClr 1,2,3")
    ("sectionToId",bo::value<std::string>()->notifier(tt::TestSectionToId),"筛选")
    ("ctPtByGeodesicDis",bo::value<std::string>()->notifier(tt::TestvfCreatPointByGeodesicDis),"由测地线距离创建点,--ctPtByGeodesicDis pointID,surfaceID,x,y,z,geodesicDis")
    // 1.18批新增接口
    ("cvLen",bo::value<std::string>()->notifier(tt::TestvfCurveLength),"曲线长度,--cvLen cvId")
    ("ctProjPt",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestvfCreatePointByProjection),"创建投影点--cvProjPt ptId surfId")
    ("gtTanOnCv",bo::value<std::string>()->notifier(tt::TestTangentOnCurve),"获取切向量--gtTanOnCv ptId cvId")
    ("hilitPtSet",bo::value<std::string>()->notifier(tt::TestHilitPointSet),"高亮点集--hilitPtSet ")
    ("clHilitPtSet",bo::value<std::string>()->notifier(tt::TestClearHilitPointSet),"去除高亮点集--clHilitPtSet ")
    ("addCmt",bo::value<std::string>()->notifier(tt::TestAddComment),"添加注释  --addCmt id ")
    ("delCmt",bo::value<std::string>()->notifier(tt::TestDelComment),"去除注释  --delCmt id ")
 ("ctGeodDisPt",bo::value<std::string>()->notifier(tt::TestGeodesicDisPoint),"--ctGeodDisPt ptId faceid dir dis ")
    ("gtGeodDis",bo::value<std::string>()->notifier(tt::TestGeodesicDis),"--gtGeodDis ptId edgeId faceid dirx diry dirz")
    ("gtIntCvs",bo::value<std::string>()->notifier(tt::TestIntersetCurves),"--gtIntCvs  edgeId")
    ("ptInProjRng",bo::value<std::string>()->notifier(tt::TestIsPointInProjectRange),"--ptInProjRng  faceid pt dir")
    ("ctLoopAndHilitFace",bo::value<std::string>()->notifier(tt::TestFindLoopAndFace),"--ctLoopAndHilitFace ")
    ("delLoopFace",bo::value<std::string>()->notifier(tt::TestDelLoopFace),"--delLoopFace loopId")
    ("splitCv",bo::value<std::string>()->notifier(tt::TestSplitCurve),"--splitCv cvId0 cvId1 splitType oriention0 oriention1 ")
    ("idMore",bo::value<std::string>()->notifier(tt::TestSectionIdToMore),"测试多选  --idMore arg")
    ("createPointNormal", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreatePointNormal), "通过点创建法线")
    ("deletePointNormal", bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestDeletePointNormal), "通过点删除法线")
    ("clrData","清除持久化的id和rosetta等数据")
    ("actDocName","get active doc name")
    ("dismantCv",bo::value<std::string>()->notifier(tt::TestDismantleCurve),"拆分曲线 --dismantCv cvId")
    ("cvStEn",bo::value<std::string>()->notifier(tt::TestCvStEn),"得曲线起终点,--cvStEn cvId")
    ("cvEqDisPts",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestEqDisPtsOnCv),"取消曲线 --cvEqDisPts cvId ptNum")
    ("ptMinDis2Surf",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestMinDisPtToSurface),"点到面最近点 --ptMinDis2Surf surfId x y z")
    ("ctLineStDir",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreateLineByPtDir ),"起点方向创建线 --ctLineStDir ptX ptY ptZ dirX dirY dirZ")
    ("ctLineStEn",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreateLineByPtStEn),"起终点创建线 --ctLineStEn stX stY stZ enX enY enZ")
    ("gtPtCoord",bo::value<std::string>()->notifier(tt::TestGetPointCoord),"取点坐标 --gtPtCoord pointId")
    ("ctSpl2d","创建二维样条曲线")
    // 2025.05.15批函数
    ("delObjs",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestBatchDelEntites),"批量删除对象 --delObjs objId1 objId2 ...")
    ("hiliSurfs",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestHilitSurfSet),"批量更改面的颜色 --hiliSurfs objId1 objId2 ...")
    ("TriOfExEndPt",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestTriOfExEndPt),"延申或修剪直线端点 --TriOfExEndPt")
    ("ctGeodCvOnSurf",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCtGeodCvByTwoPt),"在指定面上根据两点创建测地线 --ctGeodCvOnSurf ptid0 ptid1 faceid...")
    ("batchOfsCvOnSurf",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestBatchOfCvOnSurf),"批量偏移在面上的曲线 --batchOfsCvOnSurf cvId surfaceId headOfsVals(mm) tailOfsVals(mm)")
    // 2025.06.13批函数
    ("SaveDataToDoc",bo::value<std::string>()->multitoken()->notifier(tt::TestSaveDataToDoc),"DB数据存入Part文档 --SaveDataToDoc strPath")
    ("RetriveDataToDB",bo::value<std::string>()->multitoken()->notifier(tt::TestRetriveDataToDB),"DB数据存入Part文档 --RetriveDataToDB strPath")
    // 2025.07.04 批函数
    ("ctGodCvByPoint",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreatGeodesicCurvebyPoint),
    "在环内一点沿着某方向做线 --ctGodCvByPoint ptId boundaryId surfaceId dirX dirY dirZ")
    ("gtBoundByDivide",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestGetBoundaryIDbyDivide),
    "提取点所在环 --gtBoundByDivide ptId boundaryId surfId divId1 divId2"
)
   ("saveAsStp","另存为Stp")
   ("gtBoundByPoint",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestGetBoundaryIDbyPoint)
   ,"提取点所在环(数组形式输入切割线) --gtBoundByPoint ptId boundaryId surfaceId divId1 divId2 divId...")
   ("ctSlitDart",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreateSlitDart),
   "创建线性剪口 --ctSlitDart ptId1 ptId2 boundaryId surfaceId dartLength")
   ("ctVSharpDart",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCreateVShapeDart)
   ,"创建V形剪口--ctVSharpDart ptId1 ptId2 ptId3 boundaryId surfaceId")
   ("3dSection","创建三维截面")
   ("ChLinesClrWid",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestChangeLinesColorAndWidth))
   ("gtLinesClrWid",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestGetLinesColorAndWidth))
   ("join",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestJoin))
   ("gtFacePt",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestPickPointCoord))
   // 2025.10.14 
   ("CreateNewDartBoundary",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateNewDartBoundary),"创建剪口,面 边界 剪口 x y z")
   ("TestCurveOnSurface",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestCurveOnSurface),"测试曲面内 一曲线 和 环的位置关系 曲面 线 环")
   ("CreateSpliteCurve",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::CreateSpliteCurve),"分割曲线，得到曲线在曲面外的部分，依次输入面  曲线 边界")
   ("TestTypeOfSurfaceAndGetGeneratrixVector",bo::value<std::vector<std::string>>()->multitoken()->notifier(tt::TestTypeOfSurfaceAndGetGeneratrixVector),"获利面类型和母线向量,依次输入面 目标点 方向点")
    ("mbd","显示mdb树")
;

    // clang-format on
    // bo::parsed_options partOpts =
    //     bo::parse_command_line(argc, argv, desc);
    bo::command_line_parser parser{argc, argv};
    parser.options(desc);

    parser.style(bo::command_line_style::unix_style ^
                 bo::command_line_style::allow_short);
    bo::parsed_options parsed_options = parser.run();

    bo::variables_map parseResVm;
    bo::store(parsed_options, parseResVm);  
    parseResVm.notify();

    if (parseResVm.count("help") > 0) {
      std::cout << desc << std::endl;
      // desc.print(std::cout, 500);
    } else if (parseResVm.count("link") > 0) {
      tt::LinkCAD();
    } else if (parseResVm.count("clrSSet")) {
      tt::TestClearSelection();
    } else if (parseResVm.count("clrData")) {
      tt::TestClearPersistData();
    } else if (parseResVm.count("actDocName")) {
      tt::TestActiveDocName();
    } else if (parseResVm.count("ctSpl2d")) {
      tt::TestCreateSpl2d();
    } else if (parseResVm.count("saveAsStp")) {
      tt::TestSaveasStp();
    } else if (parseResVm.count("3dSection")) {
      tt::Test3dSection();
    } else if (parseResVm.count("mbd")) {
      tt::TestMBD();
    }

  } catch (const std::exception &e) {
    std::cerr << e.what() << '\n';
  }

  return 0;
}